package dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import pojo.Collection;
import pojo.Page;


public interface CollectionDao {
	//查找用户是否收藏此文章
	@Select(value="select count(*) from collection where essay_id=#{essayId} and user_id=#{userId}")
	public int selectByUserAndEssay(@Param("essayId")Integer essayId,@Param("userId")Integer userId);
	
	@Select(value="select * from collection where essay_id=#{essayId} and user_id=#{userId}")
	public Collection selectByUE(@Param("essayId")Integer essayId,@Param("userId")Integer userId);
	
	
	//查找用户收藏的文章ID
	@Select(value="select essay_id from collection where user_id=#{userId} limit #{page.currentPage},#{page.limitNumber}")
	@Results({
		@Result(column="essay_id", property="essayId")
	})
	public List<Integer> selectByUser(@Param("userId") Integer userId,@Param("page") Page page);

	//查找用户收藏的文章ID数量
	@Select(value="select count(*) from collection where user_id=#{userId}")
	public Integer selectByUserCount(@Param("userId") Integer userId);


	// 删除用户收藏的文章
	@Delete(value="delete from collection where essay_id=#{essayId} and user_id=#{userId}")
	public int deleteByUserAndEssay(@Param("essayId")Integer essayId,@Param("userId")Integer userId);
	
	//当文章被发布者删除时，删除文章
	@Delete(value="delete from collection where essay_id=#{essayId}")
	public int deleteCollectionByEssay(Integer essayId);
	
}
